import { createWebHistory, createRouter } from 'vue-router';
import HomeComp from '@/views/backendpages/HomeComp.vue';
import WelcomePage from '@/views/backendHomePages/WelcomePage.vue';
import GameForm from '@/views/createGame/GameForm.vue';
import SettingList from '@/views/settingPages/SettingList.vue';
import Illuation from '@/views/settingPages/Illuation.vue';
import Intro from '@/views/settingPages/Intro.vue';
import RuleIndex from '@/views/rulesPages/RuleIndex.vue';
import LayoutSetting from '@/views/settingPages/LayoutSetting.vue';
import BaseSetting from '@/views/baseSetting/index.vue';

const routes = [
    {
        path: '/',
        component: HomeComp,
        name: '首页布局',
        meta: {
            isCustomRouter: true,
        },
        children: [
            {
                path: '',
                component: WelcomePage,
                name: '首页',
                meta: {
                    isCustomRouter: true,
                }
            },
            {
                path: 'newGame',
                component: GameForm,
                name: '创建比赛',
                meta: {
                    isCustomRouter: true,
                }
            },
            {
                path: 'settingList',
                component: SettingList,
                name: '设置列表'
            },
            {
                path: 'illuation',
                component: Illuation,
                name: '布局管理',
            },
            {
                path: 'layoutSetting',
                component: LayoutSetting,
                name: '设置布局'
            },
            {
                path: 'introduction',
                component: Intro,
                name: '作者介绍'
            },
            {
                path: 'rule',
                component: RuleIndex,
                name: '规则配置'
            },
            {
                path:'baseSetting',
                component:BaseSetting,
                name:'基础配置'
            }
        ]
    }
];

const router = createRouter({
    history: createWebHistory(),
    routes,
});

// router.beforeEach((to, _, next) => {
//     const token = getToken();

//     // 如果要访问的不是登录页且没有token，则跳转到登录页
//     if (to.path !== '/' && !token) {
//         next('/');
//         return;
//     }

//     // 如果有token且不是访问登录页
//     if (token && to.path !== '/') {
//         // 检查路由是否存在
//         if (to.matched.length > 0) {
//             next();
//         } else {
//             next('/home/404');
//         }
//     } else {
//         // 其他情况（如访问登录页且无token），直接放行
//         next();
//     }
// });

export default router;